#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include "send.h"

#define BUF_SIZE	255


struct string {
	size_t len;
	char *s;
};

int selftest(int fd) {
	struct string test[] = {
		{ 4, "abc\n" },
		{ 4, "def\n" },
		{ 5, "adsf\n" },
		{ 5, "hihi\n" },
		{ 5, "blab\n" },
		{ 7, "wanted\n" },
		{ 8, "urandom\n" }
	};

	char buf[BUF_SIZE];
	size_t n = BUF_SIZE;
	char *lineptr = buf;

	for(size_t i = 0; i < sizeof(test); i++) {
		printf("sending: %s .. ", test[i].s);
		write(fd, test[i].s, test[i].len);
		int k = read(fd, buf, test[i].len);
		if(k == -1) {
			int err = errno;
			printf("error reading: %s\n", strerror(err));
			return (1);
		}
		if(strncmp(test[i].s, buf, k) != 0) {
			printf("strings did not match: %d\n", i);
			fwrite(buf, 1, k, stdout);
			return (1);
		}
		fwrite(buf, 1, k, stdout);
	}
}

int main(int argc, char *argv[]) {
	if(argc != 2) {
		printf("serial device required\n");
		return (1);
	}

	printf("%d %d\n", sizeof(enum z1_events), sizeof(enum z1_commands));
	return;

	int fd = open(argv[1],
		(O_RDWR),
		(S_IRUSR | S_IWUSR));

	if(fd > 0) {
		
	} else {
		printf("could not open serial device\n");
		return (1);
	}
	return (0);
}
